******************************************************************************
* Chapter 3: Party- and individual-level stability in perceptions (Temporal Dynamics section)
*
* Created: 2-19-23
* Modified: 6-18-24
*
******************************************************************************

clear 
clear matrix
clear mata
set maxvar 10000

cd "C:\Users\williamslaro\Dropbox\partyBrands\elementsText"


******************************************************************************
*** Individual Perceptions (UK Internet wave panel)
******************************************************************************

*** Load the UK Panel data
use "uk_panel.dta", clear

*** Average absolute change in perceptions across panels
gen abs_change_lr = abs(lr - lr_tm1)
tab abs_change_lr
sum abs_change_lr, det

*** Table 5: Autoregressive Distributed Lag results of the individual persistence of perceptions in the British Election Study Internet Panel
reg lr lr_tm1



******************************************************************************
*** Aggregate perceptions of parties
******************************************************************************

*** Load the Party Perceptions dataset
use "data\analyticalSample.dta", clear

* Select four main parties in the UK
keep if country == "uk"
keep if inlist(cmp, 51320, 51421, 51620, 51951)

* Generate the lags
sort cmp year month
bys cmp: gen sophiaMean_tm1 = sophiaMean[_n-1]
bys cmp: gen average_tm1 = average[_n-1]

* Table 6: Autoregressive Distributed Lag results of the aggregate persistence in British parties from 1983-2019
reg sophiaMean sophiaMean_tm1
reg average average_tm1

* Limit the figure to only one survey per year
drop if (year == 2017 & survey == "es") | (year == 2019 & survey == "ees")

* Save as an older Stata version to plot Figure 5 in R
preserve
	keep cmp year sophiaMean
	saveold "uk.dta", replace version(12)
restore	

